use std::sync::Arc;
use tokio::sync::mpsc;
use crate::actor::ActorRef;
use crate::message::{Message, DynamicMessage};
use crate::errors::SendError;

pub struct Context {
    sender: Arc<mpsc::Sender<DynamicMessage>>,
}

impl Context {
    pub fn new(sender: Arc<mpsc::Sender<DynamicMessage>>) -> Self {
        Self { sender }
    }

    pub async fn send<T: std::any::Any + Send + Clone + 'static>(&self, target: &ActorRef, msg: Message<T>) -> Result<(), SendError> {
        let dynamic_msg = msg.into_dynamic();
        target.send(dynamic_msg).await
    }

    pub async fn spawn<A: crate::actor::Actor + 'static>(&mut self, _actor: A) -> Result<ActorRef, SendError> {
        // TODO: Implement actor spawning
        unimplemented!()
    }
}
